﻿$(function () {
    window.progressDialog = new ProgressDialog();
    window.infoDialog = new InfoDialog();
    window.ajaxClass = new AjaxClass();

    window.resizeFlexiGrid = new ResizeFlexiGrid(".flexigrid", "#SettingList", ".flexigrid .bDiv", ["#TitleTR", ".flexigrid .hDiv"], 4, 4);
    $("#SettingList").flexigrid({
        colModel: [
                { display: '自动编号', name: 'SessionID', width: 250, sortable: false, align: 'left' },
                { display: '登陆名', name: 'UserID', width: 180, sortable: false, align: 'left' },
                { display: '登陆时间', name: 'LoginTime', width: 130, sortable: false, align: 'left' },
                { display: '用户姓名', name: 'UserName', width: 180, sortable: false, align: 'left' },
                { display: '锁定状态', name: 'Lock', width: 100, sortable: false, align: 'left' },
                { display: '操作', name: 'Path', width: 70, sortable: false, align: 'left' }
                ],

        width: "auto",
        height: "auto",
        resizable: false,
        showToggleBtn: false,
        striped: true,

        nonSelect: true,
        singleSelect: true,

        procmsg: '正在处理数据，请稍候……',
        nomsg: '没有符合条件的记录存在。',
        errormsg: '处理数据时出错，请与系统管理员联系！',

        onError: FlexiGrid_Error
    });
    $("#SettingList .hDiv").bind("selectstart", function () { return false; });
    window.resizeFlexiGrid.MinHeight();
    window.resizeFlexiGrid.Width();
    window.resizeFlexiGrid.Height();
    window.resizeFlexiGrid.Resize("resizeFlexiGrid");
});

function FlexiGrid_Error(XMLHttpRequest, textStatus, errorThrown) {
    infoDialog.OpenDialog("处理数据时出错，请与系统管理员联系！", "Error");
}

function Lock(SessionID) {
    var JsonSend = { "SessionID": SessionID, "ActionType": "Lock" };
    window.ajaxClass.AjaxSubmit($("#MainTable input[name='UrlAction']").val(), JsonSend, "", "SetItem('" + SessionID + "', true)", "", false, true);

}

function UnLock(SessionID) {
    var JsonSend = { "SessionID": SessionID, "ActionType": "UnLock" };
    window.ajaxClass.AjaxSubmit($("#MainTable input[name='UrlAction']").val(), JsonSend, "", "SetItem('" + SessionID + "', false)", "", false, true);
}

function SetItem(SessionID, Lock) {
    var Obj = $("#SettingList tr td div:contains(" + SessionID + ")").parent().parent();
    if (Lock) {
        Obj.find("td:eq(4) div").html("临时锁定");
        Obj.find("td:eq(5) div a:first").css("display", "none");
        Obj.find("td:eq(5) div a:last").css("display", "inline");
    } else {
        Obj.find("td:eq(4) div").html("");
        Obj.find("td:eq(5) div a:first").css("display", "inline");
        Obj.find("td:eq(5) div a:last").css("display", "none");
    }
}